<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class santri_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->CI = get_instance();
    }

    function insert($data) {
        $this->db->insert('santri', $data);
    }

    function get_santri() {
        $this->db->select("*");
        $this->db->from('santri');
        $query = $this->db->get();
        return $query;
    }

    //list flexy
    function get_data_santri() {
        //Select table name
        $table_name = "santri";

        //Build contents query
        $this->db->select('*')->from($table_name);
		
        $this->CI->flexigrid->build_query();

        //Get contents
        $return['records'] = $this->db->get();

        //Build count query
        $this->db->select('*')->from($table_name);
		$this->CI->flexigrid->build_query(FALSE);

        $return['record_count'] = $this->db->count_all_results();

        //Return all
        return $return;
    }

    function delete($id) {
        $this->db->where('ID_santri', $id);
        $this->db->delete('santri');
    }

    function selectone($id) {
        $this->db->select("*");
        $this->db->from('santri');
        $this->db->where('ID_santri', $id);
        $query = $this->db->get();
        return $query;
    }
	function get_id_santri($number, $nohp) {
        $this->db->select('*');
        $this->db->from('santri');
		$this->db->where('MUNAKOSAH', $number);
		$this->db->where('TELPON_santri', $nohp);
        $query = $this->db->get();
        return $query;
    }
		
    function update($id, $data) {
        $this->db->where('ID_santri', $id);
        $this->db->update('santri', $data);
    }
	
	function get_data_all_santri(){
		$this->db->select("*");
		$this->db->from('santri');
		$query = $this->db->get();
		return $query;
	}

	// function get_munakosah() {
        // $this->db->select_max('MUNAKOSAH');
        // $this->db->from('santri');
		// return $this->db->get()->row();
	// }
	
	function get_munakosah2() {
        $this->db->select('*');
        $this->db->from('santri');
		return $this->db->get()->result();
	}
	
	// function get_munakosah_santri($id) {
		// $this->db->select('MUNAKOSAH');
		// $this->db->from('santri');
		// $this->db->where('ID_santri', $id);
		// $this->db->get();
	}
		


?>